#include "StdAfx.h"
#include "ColorRGB.h"
#include "CoreEngine.h"
#include "GuiNode.h"
#include "TextLabel.h"

using namespace std;

namespace FEngine
{

	TextLabel::TextLabel(const string& _text, int _posX, int _posY, int _sizeX, int _sizeY, int _fontHeight, const ColorRGB& _color)
	{
		mPosition = Vector2((float)_posX, (float)_posY);
		mTextColor = _color;
		mFont = NULL;

		mText = _text;
		
		D3DXCreateFont(CoreEngine::getInstance()->getDeviceInterface(),
							 _fontHeight,      //Font height
							 0,                //Font width
							 FW_NORMAL,        //Font Weight
							 1,                //MipLevels
							 false,            //Italic
							 DEFAULT_CHARSET,  //CharSet
							 OUT_DEFAULT_PRECIS, //OutputPrecision
							 ANTIALIASED_QUALITY, //Quality
							 DEFAULT_PITCH|FF_DONTCARE,//PitchAndFamily
							 L"Arial",          //pFacename,
							 &mFont);
		
		SetRect(&mRectangleArea, (int)mPosition.x, (int)mPosition.y, _sizeX, _sizeY);
	}


	TextLabel::~TextLabel()
	{
		if (mFont)
			mFont->Release();
	}
	
	void TextLabel::setText(const std::string& _text)
	{
		mText = _text;
	}

	std::string TextLabel::getText() const
	{
		return mText;
	}

	void TextLabel::render(double _elapsedTime)
	{
		GUINode::render(_elapsedTime);

		mFont->DrawText(NULL,        //pSprite
							wstring(mText.begin(), mText.end()).c_str(),  // Text
                            -1,          //Count
                            &mRectangleArea,  //pRect
                            DT_LEFT|DT_NOCLIP,//Format,
                            0xFFFFFFFF); //Color
	}

} // namespace FEngine
